package com.mvc4g.example.mockup.client;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.mvc4g.client.Controller;
import com.mvc4g.client.Event;

public class HistoryChangeHandler implements ValueChangeHandler<String>, Constants {
	
	private Controller controller = null;
	
	public HistoryChangeHandler(Controller controller){
		this.controller = controller;
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> event) {
		String token = event.getValue();
		
		if((token != null) && (token.length() > 0)){		
			String[] tokenTab = token.split("\\?");
			String actionName = tokenTab[0];
			
			Object form = null;
			
			if(GET_EMAIL_CONTENT.equals(actionName)){
				String indexStr = tokenTab[1].split("=")[1];
				form = new Integer(indexStr);
			}
			
			Event e = new Event(actionName, form);
			controller.handleEvent(e);			
		}		
		
	}

}
